﻿using Furion.DynamicApiController;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Memory;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Furionss.Application
{
    public class CacheServices : IDynamicApiController
    {
        private const string _timeCacheKey = "cache_time";
        private readonly IMemoryCache _memoryCache;

        public CacheServices(IMemoryCache memoryCache)
        {
            this._memoryCache = memoryCache;
        }


        [ApiDescriptionSettings(KeepName = true)]
        public DateTimeOffset GetOrCreate()
        {
            return _memoryCache.GetOrCreate(_timeCacheKey, entry =>
            {
                entry.SetSlidingExpiration(TimeSpan.FromSeconds(3));
                entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(20);
                return DateTimeOffset.UtcNow;
            });
        }


    }
}
